<?php
/**
 * @author qingyu8@staff.weibo.com
 * @date 2018/08/22
 */
namespace common\tool;

use Yii;
use yii\base\BaseObject;
use EasyWeChat\Factory;

class Wechat extends BaseObject {
    public $type;

    public $app;

    public function init() {
        switch ($this->type) {
            case 'wechat':
                $config = [
                    'app_id' => Yii::$app->params['wechat']['app_id'],
                    'secret' => Yii::$app->params['wechat']['secret'],
                    // 指定 API 调用返回结果的类型：array(default)/collection/object/raw/自定义类名
                    'response_type' => 'array',
                    'log' => [
                        'level' => 'debug',
                        'file' => Yii::$app->params['env']['DATA_PATH'] . 'wechat.log',
                    ],
                ];
                $this->app = Factory::officialAccount($config);
                break;
            case 'miniProgram':
                break;
        }
    }
}
